<template>
  <layout>
    <!-- 查看文件上传内容 -->
    <!-- 顶部操作 -->
    <!-- <section slot="search"> -->
    <!-- <custom-form
        ref="search-form"
        class="search-form"
        v-model="tableSearch"
        layout="inline"
        mode="search"
        :FormList="searchColumns"
      >
        <a-button
          class="action-button"
          type="primary"
          @click="search()"
        >搜索</a-button>
        
      </custom-form> -->
    <!-- </section> -->

    <!-- 产品列表 -->
    <a-table
      :dataSource="tableData"
      :columns="tableColumns"
      :rowKey="(record) => record.member_id"
      :customRow="customTableRow"
      :pagination="false"
      size="small"
      :scroll="{
        x: '100%',
        y: 520,
      }"
      bordered
    >
      <!-- 按钮区 -->
    </a-table>

    <a-pagination
      slot="paging"
      :pageSizeOptions="pageSizes"
      :total="total"
      :show-total="showTotal"
      showSizeChanger
      :pageSize="pageSize"
      v-model="currentPage"
      @showSizeChange="changePageSize"
      @change="changePage"
    >
    </a-pagination>
  </layout>
</template>

<script lang="ts">
import { Mixins, Component, Watch, Vue, Prop } from 'vue-property-decorator'
import { State, Mutation, Getter, namespace } from 'vuex-class'
import EventsMixin from '@/mixin/events'
import { TableMixin, AuthMixin } from '@/mixin'
import { userModule } from '@/store/modules/user'

import { TableLayout } from '@/layouts'
import CustomForm from '@/components/src/Form'
import { userServices, IAdmin } from '@/common/services'
import { commonServices } from '@/common/services/common'
import { subsidyServices, IStatistics } from '@/common/services/subsidy'
import { payServices, IBankReceiptBasic } from '@/common/services/pay'
import { memberRole } from '@/common/enum'

import XLSX from 'xlsx'

const grains = [
  '水稻',
  '玉米',
  '小麦',
  '红苕',
  '马铃薯',
  '大豆',
  '绿豆',
  '豌葫豆',
  '高粱',
  '荞麦',
  '肾豆',
  '红小豆',
]

@Component({
  components: {
    Layout: TableLayout,
    CustomForm,
  },
})
export default class AdminList extends Mixins(
  EventsMixin,
  TableMixin,
  AuthMixin
) {
  @Prop({
    type: Array,
  })
  public execlData!: Array<any>

  public commonParams = {
    s_a_id: '',
  }

  // 产品列表搜索条件
  public tableSearch = {}

  // 自定义mode
  public customMode = 'search'

  // 产品列表表格信息
  public columns: ITable.IColumn[] = [
    {
      title: '大户编号',
      dataIndex: 'big_mb_id',
      key: 'big_mb_id',
      width: 120,
    },
    {
      title: '种植地行政编码',
      dataIndex: 's_a_id',
      key: 's_a_id',
      width: 120,
    },
    {
      title: '种植地行政区名',
      dataIndex: 's_a_name',
      key: 's_a_name',
      width: 240,
    },
    {
      title: '大户性质',
      dataIndex: 'big_mb_type',
      key: 'big_mb_type',
      width: 80,
    },
    {
      title: '大户名称',
      dataIndex: 'big_mb_nam',
      key: 'big_mb_nam',
      width: 180,
    },

    {
      title: '法定编码',
      dataIndex: 'big_mb_law_id',
      key: 'big_mb_law_id',
      width: 120,
    },
    {
      title: '种粮地点',
      dataIndex: 'big_mb_addr',
      key: 'big_mb_addr',
      width: 180,
    },
    {
      title: '负责人姓名',
      dataIndex: 'big_mb_user',
      key: 'big_mb_user',
      width: 100,
    },
    {
      title: '负责人身份证',
      dataIndex: 'big_mb_sfz',
      key: 'big_mb_sfz',
      width: 130,
    },
    {
      title: '负责人电话',
      dataIndex: 'big_mb_tel',
      key: 'big_mb_tel',
      width: 110,
    },

    {
      title: '开户名',
      dataIndex: 'big_mb_bank_user',
      key: 'big_mb_bank_user',
      width: 100,
    },
    {
      title: '银行账号',
      dataIndex: 'big_mb_bank_id',
      key: 'big_mb_bank_id',
      width: 130,
    },
    {
      title: '开户行',
      dataIndex: 'big_mb_bank_code',
      key: 'big_mb_bank_code',
      width: 140,
    },

    {
      title: '确权面积（亩）',
      children: [
        {
          title: '承包地',
          dataIndex: 'field1',
          key: 'field1',
          align: 'right',
          width: 80,
        },
        {
          title: '增加面积',
          dataIndex: 'field2',
          key: 'field2',
          align: 'right',
          width: 80,
        },
        {
          title: '减少面积',
          dataIndex: 'field3',
          key: 'field3',
          align: 'right',
          width: 80,
        },
      ],
    },
    {
      title: '粮食种植面积（亩）',
      dataIndex: 'plant',
      key: 'plant',
      align: 'right',
      width: 150,
    },
    ...grains.map((item, index): ITable.IColumn => {
      const key = 'plant' + (index + 1)
      return {
        title: item,
        dataIndex: key,
        key,
        width: 100,
        align: 'right',
        form: {
          type: 'a-input',
          placeholder: `请输入${item}面积`,
          // renderMode: ['plant'],
          isExport: true,
          // isShowList: false,
        },
      }
    }),
    {
      title: '购买农资花费（元）',
      dataIndex: 'material',
      key: 'material',
      align: 'right',
      width: 150,
    },
    {
      title: '农机数量(台)',
      dataIndex: 'machine',
      key: 'machine',
      align: 'right',
      width: 150,
    },
  ]

  public tableApi = {
    list: payServices.getBankReceipts,
    // add: famerServices.updateMemberGrain,
    // edit: payServices.editBankReceipt,
    // del: payServices.delBank,
    // imageUpload: 'uploadStoreImage',
    // imageRemove: 'delStoreImage'
  }

  @Watch('execlData', { immediate: true })
  public handlerChangeExecl() {
    this.total = this.execlData.length
    console.log(this.columns)
    this.getData()
  }

  public mounted() {
    // this.tableData = this.execlData || []
  }

  public handlerAddGrainColumn() {
    const grains = [
      '水稻',
      '玉米',
      '小麦',
      '红苕',
      '马铃薯',
      '大豆',
      '绿豆',
      '豌葫豆',
      '高粱',
      '荞麦',
      '肾豆',
      '红小豆',
    ]
    const grainsColumns = grains.map((item, index) => {
      const key = 'plant' + (index + 1)
      return {
        title: item,
        dataIndex: key,
        key,
        form: {
          type: 'a-input',
          placeholder: `请输入${item}面积`,
          renderMode: ['plant'],
          isExport: true,
          isShowList: false,
        },
      }
    })
    const index = this.columns.findIndex((item) => item.key === 'plant')
    if (index !== -1) {
      // @ts-ignore
      this.columns = [
        ...this.columns.slice(0, index + 1),
        ...grainsColumns,
        ...this.columns.slice(index + 1, this.columns.length - 1),
      ]
    }
  }

  public async getData() {
    // const res = await this.getTableList()
    this.tableData = this.execlData.slice(
      (this.currentPage - 1) * this.pageSize,
      this.currentPage * this.pageSize
    )
    // this.tableData = []
  }
}
</script>

<style scoped lang="less">
.action-button {
  margin: 0px 10px 0px 10px;
}
.upload-button {
  position: relative;
  input {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    z-index: 2;
    opacity: 0;
  }
}
.form-item-class {
  margin-bottom: 0px;
}
.img-box {
  width: 100px;
  height: 100px;
  margin: 10px;
}
.item-blue {
  color: #1989fa;
}
</style>
